package com.city.springcloud.service;

import com.city.springcloud.entity.Dept;
import feign.hystrix.FallbackFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Cheng
 * Date: 2020/5/8
 * Time: 22:41
 * Description: No Description
 *
 * 服务降级，处理某段时间一个服务器爆量访问，其他服务器少人访问，把少人访问的服务器降级，给爆量服务器使用
 */
public class DeptClientServiceFallbackFactory implements FallbackFactory {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {

            @Override
            public List<Dept> list() {
                //该接口以被停用，支援爆量服务，停用该接口
                List<Dept> depts=new ArrayList<>();
                Dept dept = new Dept().setDeptId(1L).setDeptName("没有对应信息，该服务消费者已被停用进行降级，请稍后访问").setDbSource("no dataSource");
                depts.add(dept);
                return depts;
            }

            @Override
            public boolean addDept(Dept dept) {
                return false;
            }
        };
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4);
        List<Integer> list2=new ArrayList<>();
        list.forEach(integer -> {
            list2.add(integer);
            list2.add(5);
        });
        list2.forEach(System.out::println);
    }
}
